unit RegDialog;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,
  cxContainer, cxEdit, dxSkinsCore, dxSkinBlack, dxSkinBlue, dxSkinCaramel,
  dxSkinCoffee, dxSkinDarkRoom, dxSkinDarkSide, dxSkinFoggy, dxSkinGlassOceans,
  dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky,
  dxSkinMcSkin, dxSkinMoneyTwins, dxSkinOffice2007Black, dxSkinOffice2007Blue,
  dxSkinOffice2007Green, dxSkinOffice2007Pink, dxSkinOffice2007Silver,
  dxSkinOffice2010Black, dxSkinOffice2010Blue, dxSkinOffice2010Silver,
  dxSkinPumpkin, dxSkinSeven, dxSkinSharp, dxSkinSilver, dxSkinSpringTime,
  dxSkinStardust, dxSkinSummer2008, dxSkinsDefaultPainters, dxSkinValentine,
  dxSkinXmas2008Blue, StdCtrls, RzLabel, cxMemo, cxTextEdit, SystemInfoUtils,
  Types, MessageDigest_5, Menus, cxButtons;

type
  TRegisterForm = class(TForm)
    cxTextEdit1: TcxTextEdit;
    cxMemo1: TcxMemo;
    RzLabel1: TRzLabel;
    RzLabel2: TRzLabel;
    cxButtonOK: TcxButton;
    cxButtonCancel: TcxButton;
    RzLabel3: TRzLabel;
    procedure FormCreate(Sender: TObject);
    procedure cxButtonOKClick(Sender: TObject);
  private
    FCameraCode: String;
    FIsRegistryed: Boolean;
  public
    constructor Create(Owner: TComponent; ACameraCode: String; isRegistryed: Boolean); overload;
  end;

var
  RegisterForm: TRegisterForm;

function GetRegApplyCode(OtherCode: String): String;

function GetRegCode(): String;

implementation

function GetRegApplyCode(OtherCode: String): String;
var
  MD5: IMD5;
begin
  MD5 := GetMD5();
  MD5.Init;
  Result := OtherCode + getCpuID() + GetMacAddress();
  MD5.Update(TByteDynArray(RawByteString(Result)),Length(Result));
  Result := UpperCase(MD5.AsString);
end;

function GetRegCode(): String;
var
  RegFilePath, S: String;
  RegCode: TStringList;
begin
  Result := '';
  RegFilePath := ExtractFilePath(Application.ExeName) + 'credit.reg';
  if FileExists(RegFilePath) then
  begin
    RegCode := TStringList.Create;
    try
      RegCode.LoadFromFile(RegFilePath);
      for S in RegCode do
        Result := Result + S;
    finally
      RegCode.Free;
    end;
  end
end;

{$R *.dfm}

constructor TRegisterForm.Create(Owner: TComponent; ACameraCode: String; isRegistryed: Boolean);
begin
  inherited Create(Owner);
  FCameraCode := ACameraCode;
  FIsRegistryed := isRegistryed;
end;

procedure TRegisterForm.cxButtonOKClick(Sender: TObject);
begin
  cxMemo1.Lines.SaveToFile(ExtractFilePath(Application.ExeName) + 'credit.reg');
end;

procedure TRegisterForm.FormCreate(Sender: TObject);
begin
  cxTextEdit1.Text := GetRegApplyCode(FCameraCode);
  cxMemo1.Text := GetRegCode();
  cxMemo1.Enabled := not FIsRegistryed;

end;

end.
